package com.crishne.anwo.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.crishne.anwo.config.ConfigInfo;
import com.crishne.anwo.constant.JsonStringConstant;
import com.crishne.anwo.dto.Pager;
import com.crishne.anwo.model.Log;
import com.crishne.anwo.service.LogService;
import com.crishne.anwo.utill.CommonUtill;

@Controller
@RequestMapping("sysmgr/log")
public class LogController {
	
	@Autowired
	private LogService logService;
	
	@Autowired
	private ConfigInfo configInfo;

	private CommonUtill commonUtill = new CommonUtill();

	//返回jsp视图
	@RequestMapping(value = "log_main")
	public String log_main(){
		return "admin/sysmgr/log_main";
	}
	
	@RequestMapping("getAllLog")
	public void getAllLog(HttpServletResponse response,HttpServletRequest request)
	{
		JSONObject jsonString = JsonStringConstant.getSuccessMessage(logService.findList(new Log()));
		commonUtill.OutputJson(jsonString,response,request);
	}
	
	@RequestMapping("getLogPageList")
	public void getLogPageList(HttpServletResponse response,HttpServletRequest request){
		//获取当前页 和 一页显示的数据数目
		String conCurrentPage = request.getParameter("currentpage");
		String stUserName = request.getParameter("userName");
		String stPageSize = request.getParameter("pageSize");
		Integer currentpage = 1;
		Integer pageSize = 10;
		if(conCurrentPage != null && !"".equals(conCurrentPage)){
			currentpage = Integer.valueOf(conCurrentPage);
		}
		
		if(stPageSize != null && !"".equals(stPageSize)){
			pageSize = Integer.valueOf(stPageSize);
		}
		
		Log tLog = new Log();
		if(null !=stUserName && !"".equals(stUserName) ){
			tLog.setStUserName(stUserName);
		}
		
		tLog.setSortColumns(" DT_LOG desc ");
		Pager logPageList = logService.findPageList(tLog, currentpage, pageSize);
		JSONObject jsonString = JsonStringConstant.getSuccessMessage(logPageList);

		commonUtill.OutputJson(jsonString, response, request);
    }

}